﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace project
{
    public partial class BalanceInquiry : Form
    
    {

    
    private  decimal balance;
        
        public BalanceInquiry()
        {
            InitializeComponent();
               
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string connection = "datasource=localhost ; port=3306; username=root;password=bebo  ";
                string query = "select Balance from  atm.account where Account_number =  '" +this.account_number.Text + "';";
                MySqlConnection con = new MySqlConnection(connection);
                MySqlCommand selectCommand = new MySqlCommand(query , con);
                MySqlDataReader reader;
                con.Open();
                reader = selectCommand.ExecuteReader();
                int count = 0;
                while (reader.Read())

                {
                      count++; 
                    this.balance = reader.GetDecimal("Balance");

                    
                }
                    if (count == 1)
                    {
                        MessageBox.Show("Your Current Balance is " + this.balance );

                    }
                    else if (count > 1)
                    {

                        MessageBox.Show("Duplicate Account Number...Access Denied  ");

                    }
                    else 
                    {

                        MessageBox.Show("Account Number Is Not Correct ! ... please try again");
                    }
                
                
                con.Close();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }

        
        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
